# syntax=docker/dockerfile:1.4
FROM ghcr.io/hqzing/docker-mini-openharmony:latest

RUN <<'EOF'
set -e

echo "coreutils 9.9
busybox 1.37.0
grep 3.12
gawk 5.3.2
make 4.4.1
ninja 1.13.1
cmake 4.1.2
m4 1.4.20
autoconf 2.72
zsh 5.9
git 2.45.2
perl 5.42.0
ruby 3.4.5" >/tmp/tools.txt

while read -r name ver; do
    file=$name-$ver-ohos-arm64.tar.gz
    curl -L -O https://github.com/Harmonybrew/ohos-$name/releases/download/$ver/$file
    tar -zxf $file -C /opt
    rm -f $file
done </tmp/tools.txt

curl -L -O https://github.com/Harmonybrew/ohos-llvm/releases/download/20251121/llvm-21.1.5-ohos-arm64.tar.gz
tar -zxf llvm-21.1.5-ohos-arm64.tar.gz -C /opt
rm -f llvm-21.1.5-ohos-arm64.tar.gz

cd /opt/llvm-21.1.5-ohos-arm64/bin
ln -s clang cc
ln -s clang gcc
ln -s clang++ c++
ln -s clang++ g++
ln -s ld.lld ld
ln -s llvm-ar ar
ln -s llvm-nm nm
ln -s llvm-objcopy objcopy
ln -s llvm-objdump objdump
ln -s llvm-ranlib ranlib
ln -s llvm-size size
ln -s llvm-strings strings
ln -s llvm-strip strip

find /opt | grep "ohos-arm64/bin$" | while IFS= read -r dir; do
    cd "$dir"
    ls | /opt/busybox-1.37.0-ohos-arm64/bin/busybox xargs -I {} sh -c "ln -s -f $(realpath {}) /bin/{}"
    cd - >/dev/null
done

EOF

CMD ["/bin/sh"]
